<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="edit-building">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label required">楼宇名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入楼宇名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required" >性别</label>
            <div class="layui-input-block">
                <select name="sex" lay-verify="required" lay-reqtext="性别不能为空">
                    <option value="">请选择</option>
                    <option value="0" >女</option>
                    <option value="1" >男</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">宿管员</label>
            <div class="layui-input-block">
                <select name="userId" id="userId"></select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="editBtn">确认编辑</button>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form','axios','layer','jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            axios = layui.axios;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(editBtn)', function (data) {
            // 选择 type="button" 的 <button> 元素和 <input> 元素
            var DISABLED = 'layui-btn-disabled';
            $(':button').addClass(DISABLED); // 添加样式
            $(':button').attr('disabled', 'disabled');  // 添加属性
            axios({
                method:"post"
                ,url:'/building/edit'
                ,data:data.field
            }).then(res=>{
                layer.msg(res.message,{
                    icon:6,
                    time: 2000 
                },function () {
                    layer.close(parentIndex);
                    layui.table.reload('building-table-id');
                    $(':button').removeClass(DISABLED);
                    $(':button').removeAttr('disabled');
                })
            }).catch(res=>{
                layer.msg("请求错误",{
                  icon:5,
                  time:2000,
                  anim:6
                })
                $(':button').removeClass(DISABLED);
                $(':button').removeAttr('disabled');
            });
            return false;
        });
    });
</script>